//
//  WNAboutusVC.swift
//  WalkNovel
//
//  Created by Kevin on 2023/8/31.
//

import UIKit

class WNAboutusVC: WNBaseVC {
    
    lazy var logoImage: UIImageView = {
       return UIImageView(image: UIImage(named: "login_logo"))
    }()
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.text = getAppName()
        label.textColor = .init(named: "black_333333")
        label.font = .wn_font(name: .bold, size: 18)
        return label
    }()
    
    lazy var verLabel: UILabel = {
        let label = UILabel()
        label.text = "Version: " + getAPPVersion()
        label.textColor = .init(named: "gray_999999")
        label.font = .wn_font(name: .bold, size: 16)
        return label
    }()
    
    lazy var copyrightLabel: UILabel = {
        let label = UILabel()
        label.text = "Wanshtoon Technology Ltd."
        label.textColor = .init(named: "gray_999999")
        label.font = .wn_font(name: .bold, size: 12)
        return label
    }()
    
    lazy var numLabel: UILabel = {
        let label = UILabel()
        label.text = "Copyright 2022"
        label.textColor = .init(named: "gray_999999")
        label.font = .wn_font(name: .bold, size: 12)
        return label
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
#if DEBUG
        logoImage.isUserInteractionEnabled = true
        let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(didTap))
        logoImage.addGestureRecognizer(tapGesture)
#endif
    }

    override func viewConfig() {
        view.addSubview(logoImage)
        view.addSubview(titleLabel)
        view.addSubview(verLabel)
        view.addSubview(copyrightLabel)
        view.addSubview(numLabel)
        logoImage.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(NaviTotalHeight+20)
            make.width.height.equalTo(120)
        }
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(logoImage.snp.bottom).offset(20)
            make.height.equalTo(26)
        }
        verLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(10)
            make.height.equalTo(22)
        }
        copyrightLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-40-TabBarMargin)
            make.height.equalTo(15)
        }
        numLabel.snp.makeConstraints { make in
            make.left.equalTo(copyrightLabel.snp.left)
            make.bottom.equalTo(-60-TabBarMargin)
            make.height.equalTo(15)
        }
        logoImage.wn_cornerWithBorder(12)
    }
    
    override func dataConfig() {
        pageName = "About Us"
        navView.titleName = "About Us"
    }
    
    @objc func didTap() {
        wn_showAlert("切换服务器环境", "当前:\(getEnvironment() ? "生产环境" : "测试环境")", "测试环境", "生产环境", firstAction: {
            saveUser(user: nil)
            saveEnvironment(false)
        }, secondAction: {
            saveUser(user: nil)
            saveEnvironment(true)
        })
    }
}
